﻿Public Class Highlighting

    Public KeywordColour As System.Drawing.Color
    Public KeywordFont As System.Drawing.Font

    Public EventnameColour As System.Drawing.Color
    Public EventnameFont As System.Drawing.Font

    Public CommandColour As System.Drawing.Color
    Public CommandFont As System.Drawing.Font

    Public EditorColour As System.Drawing.Color
    Public EditorFont As System.Drawing.Font

    Public Sub New()
        ' Create fonts and colours to use
        KeywordColour = Color.FromArgb(0, 0, 150)
        KeywordFont = New Font("Microsoft Sans Serif", 8, FontStyle.Bold, GraphicsUnit.Point)

        EventnameColour = Color.FromArgb(0, 150, 0)
        EventnameFont = New Font("Microsoft Sans Serif", 8, FontStyle.Bold, GraphicsUnit.Point)

        CommandColour = Color.FromArgb(150, 0, 50)
        CommandFont = New Font("Microsoft Sans Serif", 8, FontStyle.Bold, GraphicsUnit.Point)

        EditorColour = Color.FromArgb(0, 0, 0)
        EditorFont = New Font("Microsoft Sans Serif", 8, FontStyle.Regular, GraphicsUnit.Point)
    End Sub

    Public Sub ApplyToWord(ByVal strWord As String, ByRef txtEditArea As RichTextBox, ByVal iPosition As Integer, ByVal iLength As Integer, Optional ByVal bApplyBlank As Boolean = False)
        ' These 2 lines are the major cause of the 8 - 9 seconds per 1000 lines
        ' TODO: Find a way to make this faster
        txtEditArea.SelectionStart = iPosition
        txtEditArea.SelectionLength = iLength

        If (Commands.Contains(strWord) = True) Then
            txtEditArea.SelectionColor = CommandColour
            txtEditArea.SelectionFont = CommandFont

        ElseIf (PreprocessorCommands.Contains(strWord) = True) Then
            txtEditArea.SelectionColor = EventnameColour
            txtEditArea.SelectionFont = EventnameFont

        ElseIf (EventNames.Contains(strWord)) Then
            txtEditArea.SelectionColor = EventnameColour
            txtEditArea.SelectionFont = EventnameFont

        ElseIf (Keywords.Contains(strWord) = True) Then
            txtEditArea.SelectionColor = KeywordColour
            txtEditArea.SelectionFont = KeywordFont

        Else
            If (bApplyBlank = False) Then Return
            txtEditArea.SelectionColor = EditorColour
            txtEditArea.SelectionFont = EditorFont
        End If
    End Sub
End Class
